﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace AIS.SDK.Common
{
    public class GlobalVariables
    {

        //public static string AISServerUrl= "http://192.168.0.46:9020/jderest";

        public static string GetAISServerUrl()
        {
            //return System.Configuration.ConfigurationManager.AppSettings["AISServerUrl"].ToString();
            //return Properties.Settings.Default.AISServerUrl;
            return readAppConfig("AISServerUrl");
        }


        public static string GetAISenvironment()
        {
            //return System.Configuration.ConfigurationManager.AppSettings["AISenvironment"].ToString();
            //return Properties.Settings.Default.AISenvironment;
            return readAppConfig("AISenvironment");
        }
        /// <summary>
        /// 这里读取Config文件有点坑，
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private static string readAppConfig(string key)
        {

            string baesePath = AppDomain.CurrentDomain.BaseDirectory;
            string fullName = Path.GetFileName(Assembly.GetCallingAssembly().Location);
            string path = string.Format(@"{0}\{1}.config", baesePath, fullName);
            string configPath = AppDomain.CurrentDomain.BaseDirectory + $@"\{Path.GetFileName(Assembly.GetCallingAssembly().Location)}.config";
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap()
            {
                ExeConfigFilename = configPath
            }, ConfigurationUserLevel.None);

            //MessageBox.Show(config.AppSettings.Settings["serverIp"].Value);

            return config.AppSettings.Settings[key].Value;
        }



    }
}
